/**************************************************************
  > File Name: check_password.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2021年12月19日 星期日 18时29分19秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <crypt.h>
#include <unistd.h>
#include <string.h>
#include <shadow.h>


int main(int argc,char **argv)
{
	if (argc < 2)
	{
		fprintf(stderr,"Usage:\n");
		exit(1);
	}
	
	struct spwd *shadow_line = NULL;
	char *input_pass = NULL;
	char *Encrypted_pass = NULL;

	input_pass = getpass("Password:");
	shadow_line = getspnam(argv[1]);
	Encrypted_pass = crypt(input_pass,shadow_line->sp_pwdp);
	if (strcmp(Encrypted_pass,shadow_line->sp_pwdp) == 0)
		printf("Right\n");
	else
		printf("Error\n");



    exit(0);
}
